<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
        <#include "/pubHeadStyleTree.html">
        <script src="${ctx}/formStatic/verify.js"></script>
        <script src="${ctx}/formStatic/form/form.js"></script>
        <script src="${ctx}/formStatic/form/CommonDialog.js" type="text/javascript"></script>
            <style>
                .temTable td{
                    padding: 10px;
                }
                .uploadImgCont,.uploadFileCont{
                    text-align: center;
                }
                .subOptState{
                    width: 200px;
                    text-align: center;
                }
                .addFormTr {
                    margin-bottom: 10px;
                }
                .temTag{
                    text-align: center;
                }
            </style>
</head>
<body>
<div class="layui-form" style="height:88%;overflow: auto" lay-filter="formData" id="formDefEdit">
    <div class="layui-btn-container" style="position: absolute;left: 46%;bottom: 0;">
        <button class="layui-btn" lay-submit lay-filter="dataTemplateForm">保存</button>
        <button class="layui-btn layui-btn-danger return">取消</button>
    </div>
    <input type="hidden" id="mainTableId" name="mainTableId" value="${id}"/>
    <div class="formPreview templateAddEdit">
        <div class="temCont">
            <div class="dragGather" request="template/table">
                <div class="" style="padding: 10px">
                    <table class="temTable undefined tableExcel" border="1" width="100%" cellpadding="10" cellspacing="10">
                        <tbody request="template/table">
                        <tr class="temSpace" request="template/table">
                            <td class="dragInfo temSpace" colspan="2" rowspan="1">
                                <div class="temCont">
                                    <div class="dragGather" request="template/text">
                                        <div class="temSpace temSpaceCss">
                                            <label class="textLabel">文字</label>
                                            <input type="text" lay-verify="required" placeholder="请输入文本" autocomplete="off" class="layui-input textInput" name="m:demozb:wz" maxlength="50" value="">
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr class="temSpace" request="template/table">
                            <td class="dragInfo temSpace">
                                <div class="temCont">
                                    <div class="dragGather" request="template/date">
                                        <div class="temSpace temSpaceCss">
                                            <label class="dateLabel">开始时间</label>
                                            <input type="text" placeholder="请选择日期" autocomplete="off" class="layui-input dateInput temDate" id="startTime" name="m:demozb:kssj" displaydate="0" format="yyyy-MM-dd" datetype="date" lay-key="1" value="">
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="dragInfo temSpace">
                                <div class="temCont">
                                    <div class="dragGather" request="template/date">
                                        <div class="temSpace temSpaceCss">
                                            <label class="dateLabel">结束时间</label>
                                            <input type="text" placeholder="请选择日期" autocomplete="off" class="layui-input dateInput temDate" id="endTime" name="m:demozb:jssj" displaydate="0" format="yyyy-MM-dd" datetype="date" lay-key="2" value="">
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr class="temSpace" request="template/table">
                            <td class="dragInfo temSpace">
                                <div class="temCont">
                                    <div class="dragGather" request="template/uploadFile">
                                        <div class="temSpace temSpaceCss">
                                            <label class="uploadFileLabel">附件上传</label>
                                            <div class="uploadFileCont" val="">
                                                <button type="button" class="layui-btn uploadFileBtn" filetypes=".doc;.txt;.sql;.xml" isinit="2"> 上传附件 </button>
                                                <input class="layui-upload-file" type="file" accept="" name="file" multiple>
                                                <ul class="uploadFileList" name="m:demozb:fjsz">
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="dragInfo temSpace">
                                <div class="temCont">
                                    <div class="dragGather" request="template/uploadImg">
                                        <div class="temSpace temSpaceCss">
                                            <label class="uploadImgLabel">图片上传</label>
                                            <div class="uploadImgCont" val="">
                                                <button type="button" class="layui-btn uploadImgBtn" isinit="2"> 上传图片 </button>
                                                <input class="layui-upload-file" type="file" accept="" name="file" multiple>
                                                <ul class="uploadImgList" name="m:demozb:tpsz">
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="temCont">
            <div class="dragGather" request="template/table">
                <div class="" style="padding: 10px">
                    <a modetype="2" class="addFormTr layui-btn layui-btn-sm">新增</a>
                    <table class="temTable demozib subFormTable"  border="1" width="100%" cellpadding="10" cellspacing="10">
                        <tbody request="template/table">
                        <tr class="temSpace" request="template/table">
                            <td class="temSpace">
                                <div class="temCont">
                                    <div class="dragGather" request="template/tag">
                                        <div class="temSpace temSpaceCss">
                                            <div class="temTag">
                                                序号
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="temCont">
                                    <div class="dragGather" request="template/tag">
                                        <div class="temSpace temSpaceCss">
                                            <div class="temTag">
                                                子表文字
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="temCont">
                                    <div class="dragGather" request="template/tag">
                                        <div class="temSpace temSpaceCss">
                                            <div class="temTag">
                                                子表开始时间
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="temCont">
                                    <div class="dragGather" request="template/tag">
                                        <div class="temSpace temSpaceCss">
                                            <div class="temTag">
                                                子表结束时间
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="temCont">
                                    <div class="dragGather" request="template/tag">
                                        <div class="temSpace temSpaceCss">
                                            <div class="temTag">
                                                子表附件上传
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="temCont">
                                    <div class="dragGather" request="template/tag">
                                        <div class="temSpace temSpaceCss">
                                            <div class="temTag">
                                                子表图片上传
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subOptState">
                                <div class="temCont">
                                    <div class="dragGather" request="template/tag">
                                        <div class="temSpace temSpaceCss">
                                            <div class="temTag">
                                                管理
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr class="temSpace subContTem" style="display: none" request="template/table">
                            <td class="temSpace">
                                <div class="temCont">
                                    <div class="dragGather" request="template/tag">
                                        <div class="temSpace temSpaceCss">
                                            <div class="temTag">
                                                0
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/text">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="textLabel">子表文字</label>-->
                                                <input type="text" placeholder="请输入文本" autocomplete="off" class="layui-input textInput" name="s:demozib:zbwz" maxlength="50" value="">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/date">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="dateLabel">子表开始时间</label>-->
                                                <input type="text" placeholder="请选择日期" autocomplete="off" class="layui-input dateInput temDate start" name="s:demozib:zbkssj" displaydate="0" format="yyyy-MM-dd" datetype="date" lay-key="3" value="">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/date">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="dateLabel">子表结束时间</label>-->
                                                <input type="text" placeholder="请选择日期" autocomplete="off" class="layui-input dateInput temDate end" name="s:demozib:zbjssj" displaydate="0" format="yyyy-MM-dd" datetype="date" lay-key="4" value="">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                    <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/uploadFile">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="uploadFileLabel">子表附件上传</label>-->
                                                <div class="uploadFileCont" val="">
                                                    <button type="button" class="layui-btn uploadFileBtn" filetypes=".doc;.txt;.sql;.xml" isinit="2"> 上传附件 </button>
                                                    <input class="layui-upload-file" type="file" accept="" name="file" multiple>
                                                    <ul class="uploadFileList" name="s:demozib:zbfjsz">
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/uploadImg">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="uploadImgLabel">子表图片上传</label>-->
                                                <div class="uploadImgCont" val="">
                                                    <button type="button" class="layui-btn uploadImgBtn" isinit="2"> 上传图片 </button>
                                                    <input class="layui-upload-file" type="file" accept="" name="file" multiple>
                                                    <ul class="uploadImgList" name="s:demozib:zbtpsz">
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div> </td>
                            <td class="temSpace subOptState"><a class="layui-btn layui-btn-sm subDeleteTr">删除</a><a class="layui-btn layui-btn-sm subUpTr">上移</a><a class="layui-btn layui-btn-sm subDownTr">下移</a></td>
                        </tr>
                        <tr class="temSpace" request="template/table">
                            <td class="temSpace">
                                <div class="temCont">
                                    <div class="dragGather" request="template/tag">
                                        <div class="temSpace temSpaceCss">
                                            <div class="temTag">
                                                1
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/text">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="textLabel">子表文字</label>-->
                                                <input type="text" placeholder="请输入文本" autocomplete="off" class="layui-input textInput" name="s:demozib:zbwz" maxlength="50" value="">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/date">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="dateLabel">子表开始时间</label>-->
                                                <input type="text" placeholder="请选择日期" autocomplete="off" class="layui-input dateInput temDate start" name="s:demozib:zbkssj" displaydate="0" format="yyyy-MM-dd" datetype="date" lay-key="5" value="">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/date">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="dateLabel">子表结束时间</label>-->
                                                <input type="text" placeholder="请选择日期" autocomplete="off" class="layui-input dateInput temDate end" name="s:demozib:zbjssj" displaydate="0" format="yyyy-MM-dd" datetype="date" lay-key="6" value="">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/uploadFile">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="uploadFileLabel">子表附件上传</label>-->
                                                <div class="uploadFileCont" val="">
                                                    <button type="button" class="layui-btn uploadFileBtn" filetypes=".doc;.txt;.sql;.xml" isinit="2"> 上传附件 </button>
                                                    <input class="layui-upload-file" type="file" accept="" name="file" multiple>
                                                    <ul class="uploadFileList" name="s:demozib:zbfjsz">
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subDialogShowState">
                                <div class="dragSourceInfo">
                                    <div class="temCont">
                                        <div class="dragGather" request="template/uploadImg">
                                            <div class="temSpace temSpaceCss">
                                                <!--<label class="uploadImgLabel">子表图片上传</label>-->
                                                <div class="uploadImgCont" val="">
                                                    <button type="button" class="layui-btn uploadImgBtn" isinit="2"> 上传图片 </button>
                                                    <input class="layui-upload-file" type="file" accept="" name="file" multiple>
                                                    <ul class="uploadImgList" name="s:demozib:zbtpsz">
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="temSpace subOptState"><a class="layui-btn layui-btn-sm subDeleteTr">删除</a><a class="layui-btn layui-btn-sm subUpTr">上移</a><a class="layui-btn layui-btn-sm subDownTr">下移</a></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'setter', 'ice', 'form', 'element', 'layer', 'slider', 'colorpicker','laydate', 'form', 'totalFilter', 'propsHandle', 'commons','util'], function () {
        var $ = layui.$,
            setter = layui.setter,
            layer = layui.layer,
            ice = layui.ice,
            util = layui.util,
            laydate = layui.laydate,
            propsHandle = layui.propsHandle,
            form = layui.form,
            commons = layui.commons,
            defProps = {
                viewMould: serverPath.formPath + '/form/formDef/view/formDesign/moulds/',
                initCss: [
                    'style/forms/grid/grid1',
                    'style/forms/grid/grid2',
                    'style/forms/grid/grid3',
                    'style/forms/template/tag',
                    'style/forms/template/text',
                    'style/forms/template/table',
                    'style/forms/template/textArea',
                    'style/forms/template/radioOption',
                    'style/forms/template/date',
                    'style/forms/template/button',
                    'style/forms/template/uploadFile',
                    'style/forms/template/richText',
                    'style/forms/template/select',
                    'style/forms/template/checkOption',
                    'style/forms/template/dataLexi',
                    'style/forms/template/uploadImg',
                    'style/forms/template/selector',
                    'style/forms/formDevise',
                    'style/forms/dragLay',
                    'style/forms/formPreview'
                ],
                formAreaInfo: 'html',
                temDate: '.temDate',
                uploadFileBtn: '.uploadFileBtn',
                uploadImgBtn: '.uploadImgBtn',
                richTextArea: '.richTextArea',
                selectInput: '.selectInput',
                radioOptionCont: '.radioOptionCont',
                dataLexiTree: '.dataLexiTree',
                selectorBtn: '.selectorBtn'
            },
            temQuery = new propsHandle()
        ;
        ice.loadCss(defProps.initCss);


        var id = '${id}';
        $.ajax({
            url: serverPath.basePath + '/demo/wDemozb/get',
            type: "POST",
            dataType: 'json',
            data: {"mainTableId":id},
            success: function (result) {
                if (commons._filterRecord(result)) {
                    console.log(result);
                    var mainData = result.data.wDemozb;
                    var subData = result.data.subList;

                    $(".selectorInfo").each(function () {
                        var inputObj = $(this).children();
                        if ($(this).children().attr("name") != undefined) {
                            var name = $(this).children().attr("name").split(":");
                            var selectorId = name[2] + "id";
                            inputObj.val(mainData[name[2].toLocaleLowerCase()]);
                            inputObj.attr("ids", mainData[selectorId.toLocaleLowerCase()]);
                        }
                    });
                    if (id) {

                        $("input[name^='m:'].textInput").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            $(this).val(mainData[fieldName.toLocaleLowerCase()]);
                        });
                        $("input[name^='m:'].temDate").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            $(this).val(util.toDateString(mainData[fieldName.toLocaleLowerCase()], $(this).attr('format')));
                        });

                        $("textarea[name^='m:'].textAreaInput").each(function () {
                            var value = $(this).text();
                            var reg=new RegExp("<br/>","g");
                            value = value.replace(reg,"\r\n");
                            $(this).text(value);
                        });

                        //富文本回显
                        $("div[name^='m:'].richTextCont").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            $(this).find("textarea").text(mainData[fieldName.toLocaleLowerCase()]);
                        });

                        $(".radioOptionCont").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            $(this).find('input:radio').each(function () {
                                    if ($(this).val() == mainData[fieldName.toLocaleLowerCase()]) {
                                        $(this).prop('checked', true);
                                    }
                                }
                            )
                        });
                        $(".checkOptionCont").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            $(this).find('input:checkbox').each(function () {
                                var fieldVal = mainData[fieldName.toLocaleLowerCase()];
                                if (fieldVal != null && fieldVal.indexOf($(this).val()) > -1) {
                                    $(this).prop("checked", true);
                                }
                            })
                        });

                        $("input[name^='m:'].dataLexiVal").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            if($(this).attr("dictype")==="0"){
                                $(this).parents(".lexiTree").next().find("option").each(function (ind,elem) {
                                    if($(elem).text() === mainData[fieldName]) {
                                        $(elem).attr("selected", true);
                                    }
                                });
                            }else{
                                $(this).prev().text(mainData[fieldName.toLocaleLowerCase()]);
                            }

                        });

                        $(".uploadFileList").each(function () {
                            var name = $(this).attr('name');
                            var fieldName = name.replace(/.*:/, '');
                            var flag = getUploadFileIsMain(subData, $(this));
                            if (flag) {
                                if (mainData[fieldName.toLocaleLowerCase()] != "" && mainData[fieldName.toLocaleLowerCase()] != undefined) {
                                    var fileIdArray = JSON.parse(mainData[fieldName.toLocaleLowerCase()]);
                                    if (fileIdArray.length > 0) {
                                        for (var i = 0; i < fileIdArray.length; i++) {
                                            var str = '<li fileId=' + fileIdArray[i]["fileid"] + '><p onclick="downFile(this)">' + fileIdArray[i]["name"] + '</p><i class="layui-icon layui-icon-delete deleteFile" ></i></li>';

                                            $(this).append(str);
                                        }
                                    }
                                }
                            }
                        });

                        $(".uploadImgList").each(function () {
                            var name = $(this).attr('name');
                            var fieldName = name.replace(/.*:/, '');
                            var flag = getUploadFileIsMain(subData, $(this));
                            if (flag) {
                                if (mainData[fieldName.toLocaleLowerCase()] != "" && mainData[fieldName.toLocaleLowerCase()] != undefined) {
                                    var fileIdArray = JSON.parse(mainData[fieldName.toLocaleLowerCase()]);
                                    if (fileIdArray.length > 0) {
                                        for (var i = 0; i < fileIdArray.length; i++) {
                                            var str = '<li fileId=' + fileIdArray[i] + '><div class="fileByImg"><img src="' + serverPath.formPath + setter.sysLinkPath + 'attachFile/getFileById?fileId=' + fileIdArray[i] + '" /></div><i class="layui-icon layui-icon-delete deleteFile" ></li>'

                                            $(this).append(str);
                                        }
                                    }
                                }
                            }
                        });

                        form.render();
                    }





                    if (subData) {
                        processSubData(subData);
                    }
                    temQuery.initTemEvent(defProps, serverPath, setter);



                    $("input[name^='m:'].dataLexiVal").each(function () {
                        var name = $(this).attr("name").split(":");
                        var fieldName = name[2];
                        if($(this).attr("dictype")==="0"){
                            $(this).parents(".lexiTree").next().find("option").each(function (ind,elem) {
                                if($(elem).text() === mainData[fieldName]) {
                                    $(elem).attr("selected", true);
                                }
                            });
                        }
                    });
                    if (subData) {
                        for (var i = 0; i < subData.length; i++) {
                            var subTableName = subData[i].tableName;
                            var dataList = subData[i].wDemozibList;
                            var inputName = "s:" + subTableName;
                            for (var j = 0; j < dataList.length; j++) {
                                var trObjs = $("." + subTableName + " tr.temSpace");
                                var jsonObj = dataList[j];
                                for (var key in jsonObj) {
                                    var attrName = inputName + ":" + key;
                                    var inputObj = $(trObjs[j + 2]).children().find("input[name='" + attrName + "']");
                                    var objVal = jsonObj[key];

                                    if (inputObj.length > 0) {
                                        if (inputObj.hasClass("dataLexiVal")) {
                                            if(inputObj.attr("dictype")==="0"){
                                                inputObj.parents(".lexiTree").next().find(".lexiSelectCont option").each(function (ind,elem) {
                                                    if($(elem).text() === objVal) {
                                                        $(elem).attr("selected", true);
                                                    }
                                                });
                                            }
                                        }
                                    }

                                }
                            }

                        }
                        if(mainData){
                            $("input[name^='s:'].temDate").each(function () {
                                var name = $(this).attr("name").split(":");
                                var fieldName = name[2];
                                $(this).val(util.toDateString(mainData[fieldName.toLocaleLowerCase()], $(this).attr('format')));
                            });
                        }


                    }

                    form.render();
                } else {
                    window.parent.layer.alert(result.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert("预览失败！" + XMLHttpRequest.status);
            }
        });

        form.verify({
            required: function (value, item) {
                var tr = $(item).parents("tr");
                if(tr.hasClass("subContTem")){
                }else{
                    var fieldValue = $(item).val();
                    if (fieldValue == "") {
                        return '必填项不能为空';
                    }
                }
            }

        });

        temQuery.initTem({
            selectorBtn: defProps.selectorBtn,
            selectorTemPath: setter.views + defProps.viewMould
        });

        var index = parent.layer.getFrameIndex(window.name);
        $('.return').click(function () {
            parent.layer.close(index);
        });

        form.on('submit(dataTemplateForm)', function (data) {
            window.needVer = '';
            data.field.formData = getData();
            $.ajax({
                url: serverPath.basePath + '/demo/wDemozb/save',
                type: "POST",
                dataType: 'json',
                async:false,
                data: data.field,
                success: function (result) {
                    if (commons._filterRecord(result)) {
                        window.parent.layer.alert(result.msg, function (thisIndex) {
                            parent.layui.table.reload('templateTable',
                                {
                                    page: {curr: 1}
                                });
                            parent.layui.totalFilter.init('templateTable');
                            commons._bulletWindow(thisIndex);
                            parent.layer.close(index);
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else {
                        window.parent.layer.alert(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("保存失败！" + XMLHttpRequest.status);
                }
            });
            return false;
        });

        function getUploadFileIsMain(subData, obj) {
            var flag = true;
            for (var p = 0; p < subData.length; p++) {
                var subTableName = subData[p].tableName;
                var tableClass = "temTable " + subTableName + " subFormTable";
                if ($(obj).parents("table ." + tableClass).length > 0) {
                    flag = false;
                }
            }
            return flag;
        }
        function processSubData(subData) {
            for (var h = 0; h < subData.length; h++) {

                var subTableName = subData[h].tableName;
                var dataList = subData[h].wDemozibList;
                for (var k = 0; k < dataList.length; k++) {
                    if (k > 0) {
                        var cloneTr = $("." + subTableName + " tr.temSpace");
                        var trLength = cloneTr.length;
                        $(cloneTr[trLength - 1]).clone().appendTo("." + subTableName);
                        var cloneTr = $("." + subTableName + " tr.temSpace");
                        var index = cloneTr.length-2;
                        $(cloneTr[cloneTr.length-1]).find("div.temTag").text(index);
                        var radioDiv = $(cloneTr[cloneTr.length-1]).find("div.radioOptionCont");
                        radioDiv.find('input:radio').each(function () {
                            var attrName = $(this).attr("name");
                            var indexStr = "_"+(index-1).toString();
                            var newIndexStr = "_"+index.toString();
                            if(attrName.indexOf(indexStr) > -1){
                                attrName= attrName.replace(indexStr,newIndexStr);
                            }else{
                                attrName= attrName+newIndexStr;
                            }
                            $(this).attr("name",attrName);
                        })
                    }
                }
            }
            for (var i = 0; i < subData.length; i++) {
                var subTableName = subData[i].tableName;
                var dataList = subData[i].wDemozibList;
                var inputName = "s:" + subTableName;
                for (var j = 0; j < dataList.length; j++) {
                    var trObjs = $("." + subTableName + " tr.temSpace");
                    var jsonObj = dataList[j];
                    for (var key in jsonObj) {
                        var attrName = inputName + ":" + key;
                        var inputObj = $(trObjs[j + 2]).children().find("input[name='" + attrName + "']");
                        var selectObj = $(trObjs[j + 2]).children().find("select[name='" + attrName + "']");
                        var divObj = $(trObjs[j + 2]).children().find("div[name='" + attrName + "']");
                        var ulObj = $(trObjs[j + 2]).children().find("ul[name='" + attrName + "']");
                        var objVal = jsonObj[key];
                        if (selectObj.length > 0) {
                            $(selectObj).val(objVal);
                        }
                        if (inputObj.length > 0) {
                            $(inputObj).val(objVal);
                            if (inputObj.hasClass("selectorInput")) {
                                var selectorId = key + "id";
                                inputObj.attr("ids", jsonObj[selectorId]);
                            }
                            if (inputObj.hasClass("dataLexiVal")) {
                                if(inputObj.attr("dictype")==="0"){
                                    //inputObj.parents(".temCont").find(".lexiSelectCont option:contains('"+objVal+"')").attr("selected",true);
                                    inputObj.parents(".lexiTree").next().find(".lexiSelectCont option").each(function (ind,elem) {
                                        if($(elem).text() === objVal) {
                                            $(elem).attr("selected", true);
                                        }
                                    });
                                }else{
                                    inputObj.prev().text(objVal);
                                }
                            }
                        }
                        if (ulObj.length > 0) {
                            var fileIdArray = JSON.parse(objVal);
                            for (var g = 0; g < fileIdArray.length; g++) {
                                var str = '<li fileId=' + fileIdArray[g]["fileid"] + '><p>' + fileIdArray[g]["name"] + '</p><i class="layui-icon layui-icon-delete deleteFile" ></i></li>';
                                if (ulObj.hasClass("uploadImgList")) {
                                    str = '<li fileId=' + fileIdArray[g] + '><div class="fileByImg"><img src="' + serverPath.formPath + setter.sysLinkPath + 'attachFile/getFileById?fileId=' + fileIdArray[g] + '" /></div><i class="layui-icon layui-icon-delete deleteFile" ></li>'
                                }

                                ulObj.append(str);
                            }
                        }
                        if (divObj.length > 0) {
                            divObj.find('input:checkbox').each(function () {
                                if (objVal != null && objVal.indexOf($(this).val()) > -1) {
                                    $(this).prop("checked", true);
                                }
                            });
                            divObj.find('input:radio').each(function () {
                                if ($(this).val() === objVal) {
                                    $(this).prop('checked', true);
                                }
                            })
                            //富文本
                            divObj.find('textarea').text(objVal);
                        }
                        var textareaObj = $(trObjs[j + 2]).children().find("textarea[name='" + attrName + "']");
                        // var regExp=new RegExp("<br/>","g");
                        // var textVal = objVal.replace(regExp,"\r\n");
                        $(textareaObj).val(objVal);
                    }
                }
                $(".temDate.start").each(function (i) {
                    commons.reflashDate({startName:$(".temDate.start")[i],endName:$(".temDate.end")[i]})
                })
            }
            form.render();
        };
        temQuery.initSubEvent(defProps, serverPath, setter)
        commons.reflashDate({startName:'#startTime',endName:'#endTime'});

        $('.addFormTr').click(function(){
            var leng = $(".temDate.start").length;
            setTimeout(function () {
                var start = $(".temDate.start")[leng];
                var end = $(".temDate.end")[leng];
                var newS = $(start).clone();
                var newE = $(end).clone();
                $(start).before(newS);
                $(end).before(newE);
                $(start).remove()
                $(end).remove()
                commons.reflashDate({startName:newS[0],endName:newE[0]},'',function () {
                    newS.click(function () {
                        return false;
                    })
                    newE.click(function () {
                        return false;
                    })
                }());

            },0)



        });
    });

    //按钮权限处理-根据权限继承字段
    setTimeout(function () {
        $(":button").each(function(){
            if($(this).hasClass("temButton")){
                var powerInherit = JSON.parse($(this).attr('dialoginstall')).powerInherit;
                var inheritField = $("input[name$=':"+powerInherit+"']");
                if(inheritField.length<=0){
                    $(this).css("display","none");
                }
                if(inheritField.attr("disabled")){
                    $(this).attr("disabled",true);
                }
            }
        })
    },1000)
</script>
</body>
</html>


